package com.liu.jbase.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.springframework.format.Formatter;

public class DateFormatter implements Formatter<Date> {
	
    private SimpleDateFormat dateFormat;
    public DateFormatter(String datePattern){

        dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
    
    @Override
    public String print(Date date,Locale locale){
        System.out.println("Date转String类型执行中。。。。");
        return dateFormat.format(date);
    }
    
    @Override
    public Date parse(String source,Locale locale) throws ParseException{
        try{
            System.out.println("字符串转Date类型执行中。。。。");
            return dateFormat.parse(source);
        }catch(Exception ex){
            ex.printStackTrace();
            throw new IllegalArgumentException();
        }
    }
}
